<template>
  <div v-if="browserRedirect">
    <div>
      <div class="table-page-search-wrapper" v-show="showSizer">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">   
            <a-col :md="6" :sm="8">
              <a-form-item label="剧本名称">
                <a-input placeholder="请输入剧本名称" v-model="goodName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8" >
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <a-tabs default-active-key="1" size="large" :tab-bar-style="{marginBottom: '24px', paddingLeft: '16px'}">
        <div class="extra-wrapper" slot="tabBarExtraContent">
          <div class="selSty" @click="showSizer=!showSizer" style="line-height: 60px;">
            <span>筛选</span>
            <img style='margin-top: -3px;margin-left: 3px;' src="../../assets/common-icon-filter.svg">
          </div>
        </div>
        <a-tab-pane loading="true" tab="正版剧本绑定概览" key="1" style="min-height: 100vh;">
          <ul style="margin: 0;padding:0;list-style-type: none;">
            <li v-for="val in dataSource" class="liCommSty">
              <div style="border-bottom: 1px solid #EBEBEB;padding-bottom: 10px;">
                <div style="color: #333;font-weight: bold;">
                  <span>{{val.goodName}}</span>
                </div>
              </div>
              <div style="margin-top: 10px;">
                <span style="color: #333;">店家使用人数</span>
                <span style="float: right;">{{val.userSignNum}}</span>
              </div>
            </li>
          </ul>
          <a-pagination style="float: right;margin-top:5px;" showQuickJumper :defaultCurrent="ipagination.current" :total="ipagination.total" @change="onChange"/>
        </a-tab-pane>
      </a-tabs>
    </div>
  </div>
  <a-card v-else :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
 
          <a-col :md="6" :sm="8">
            <a-form-item label="剧本名称">
              <a-input placeholder="请输入剧本名称" v-model="goodName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8" >
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
 

        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    
   

    <!-- table区域-begin -->
    <div>
      <a-table
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="图片不存在" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
         

          <a-divider type="vertical" />
           
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
               
        </span>

      </a-table>
    </div>
  </a-card>
</template>

<script>
  import { getAction } from '@/api/manage'
  import { browserRedirect } from '@/utils/util'
  export default {
    name: "BlockCustomerSearchList",  
    components: {
    },
    data () {
      return {
        browserRedirect:false,
        showSizer:false,
        description: '店家搜索历史表管理页面',
        issuerId:"",
        goodName:"",
        dataSource:[],
        ipagination: {
          current: 1,
          pageSize: 10,
          showSizeChanger:false,
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          total: 0
        },
        // 表头
        columns: [
          {
            title:'剧本名称',
            align:"center",
            dataIndex: 'goodName'
          },
          {
            title:'店家使用总人数',
            align:"center",
            dataIndex: 'userSignNum'
          }
        ],
        userAuth2btn:"",
        dictOptions:{
        },
      }
    },
    mounted(){
      var that = this;
      this.browserRedirect = browserRedirect();
      getAction("/block/blockManufacturerInfo/userAuth2btn")
        .then(res => {
          if (res.success) {
            that.userAuth2btn = res.result.status;
            if(that.userAuth2btn == 3){
              that.issuerId = "";
              this.listInfo();
              return
            }
            let list={
              column: "createTime",
              order: "desc",
              field: "id,,factoryName,companyProfile,createTime,type,name,status,address,phone,imageurl,action",
              pageNo: 1,
              pageSize: 5
            };
            getAction("/block/blockManufacturerInfo/list",list).then((res)=>{
              if (res.success) {
                this.issuerId = res.result.records[0].id;
                this.listInfo();
              } else {
                this.$message.warning(res.message)
              }
            })
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          // this.loading = false
        }) 
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      onChange(pageNumber) {
        this.ipagination.current = pageNumber;
        this.handleTableChange(this.ipagination,{},{});
      },
      listInfo(){
        getAction("https://blockinsight.com.cn/scriptPlay/third/goodHistorySee?currentPage=1&pageSize=10&issuerId="+this.issuerId).then((res) => {
          if (res.success) {
            this.dataSource = res.data.data;
            this.ipagination.total = res.data.totalSize;
          }
          if(res.code===510){
            this.$message.warning(res.message)
          }
        })
      },
      searchReset(){
        this.goodName = "";
        this.searchQuery();
      },
      searchQuery(){
        this.ipagination.current = 1;
        getAction("https://blockinsight.com.cn/scriptPlay/third/goodHistorySee?currentPage=1&pageSize=10&goodName="+this.goodName+"&issuerId="+this.issuerId).then((res) => {
          if (res.success) {
            this.dataSource = res.data.data;
            this.ipagination.total = res.data.totalSize;
          }
          if(res.code===510){
            this.$message.warning(res.message)
          }
        })
      },
      handleTableChange(pagination, filters, sorter){
        this.ipagination = pagination;
        getAction("https://blockinsight.com.cn/scriptPlay/third/goodHistorySee?currentPage="+pagination.current+"&pageSize=10&goodName="+this.goodName+"&issuerId="+this.issuerId).then((res) => {
          if (res.success) {
            this.dataSource = res.data.data;
            this.ipagination.total = res.data.totalSize;
          }
          if(res.code===510){
            this.$message.warning(res.message)
          }
        })
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>